package com.example.lots_of_demo.handler;

import com.example.lots_of_demo.model.REnum;
import com.example.lots_of_demo.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/12
 */
@Slf4j
//@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R resolveException(HttpServletRequest request, Exception ex) throws Exception {
        log.info(request.getRemoteAddr() + "访问发生异常-------------------------");
        log.error(ex.getMessage());
        return R.createFail(REnum.RFailResponse.SERVER_EXCEPTION_RESPONSE);
    }
}
